import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * UnassignClubWindow.java
 * 
 * Provides a window to provide a list of clubs to unassign
 * 
 * @author Steven Glazer
 * @author Kyle Marcotte
 * @author Sam Milton
 */
public class UnassignClubWindow extends JDialog implements ActionListener {
	
	private static final long serialVersionUID = -1987272389263189086L;
	
	// Class Variables
	private final int HGAP = 12;
	private final int VGAP = 12;
	
	private JList listData;
	private JScrollPane listDataScroll;
	private JPanel pane;
	private JPanel buttonPane;
	private JButton selectBut;
	private JButton cancelBut;
	private boolean selected = false;
	
	/**
	 * Constructor
	 */
	public UnassignClubWindow(JFrame parent, boolean modal, String[] data) {
		super(parent, modal);
		this.setTitle("Unassign Club");
		pane = (JPanel)this.getContentPane();
		pane.setLayout(new BorderLayout(HGAP, VGAP));
		pane.setBorder(BorderFactory.createEmptyBorder(VGAP, HGAP, VGAP, HGAP));
		
		buttonPane = new JPanel();
		buttonPane.setLayout(new GridLayout(1, 2, HGAP, VGAP));
		
		listData = new JList(data);
		listDataScroll = new JScrollPane(listData);
		selectBut = new JButton("Select");
		selectBut.addActionListener(this);
		cancelBut = new JButton("Cancel");
		cancelBut.addActionListener(this);
		
		
		buttonPane.add(selectBut);
		buttonPane.add(cancelBut);
		
		pane.add(listDataScroll, BorderLayout.CENTER);
		pane.add(buttonPane, BorderLayout.SOUTH);
		
		this.pack();
		this.setLocationRelativeTo(parent);
		this.setVisible(true);
	}
	
	/**
	 * actionPerformed method from ActionListener
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == selectBut)
			selected = true;
		this.setVisible(false);
	}
	
	/**
	 * Returns the index of the selected club to unassign
	 * 
	 * @return	Index of club
	 */
	public int getResult() {
		if(selected)
			return listData.getSelectedIndex();
		else
			return -1;
	}
}
